package sketch.seg.cd.exp;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import sketch.doc.Sketch;
import sketch.doc.SketchContainer;
import sketch.ink.SampledPoint;
import sketch.ink.Stroke;
import sketch.shape.geom.prim.Point;

public class StrokeFormater {

	private String inputFileName;

	private String outputFileName;

	public StrokeFormater(String filename) {
		inputFileName = filename;
		outputFileName = inputFileName + ".input";
	}

	public void output() {
		try {
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outputFileName))));

			Sketch sketch = SketchContainer.get().open();
			sketch.readFromFile(new File(inputFileName));

			Stroke s = sketch.getStrokes().get(0);
			for (SampledPoint p : s.getPoints()) {
				bw.write(p.getX() + "\t" + p.getY() + "\n");
			}

			bw.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		String prefix = "./exp/zhengwt/zhengwt.seg.";
		for (int i = 1; i <= 20; i++) {
			String input = prefix + Integer.toString(i);
			new StrokeFormater(input).output();
		}
	}
}
